import App from './App'
import {
	createPinia
} from 'pinia'
import tui from './common/httpRequest'

const showLoading = function(loadConfig) {
	if (!loadConfig) {
		loadConfig = {
			type: 'global',
			text: '正在加载...',
			backgroundImage: 'https://qiniu.zdbty.net/g8LtkTUpJjDh.gif'
		}
	}
	store.commit('loading/showLoading', loadConfig)
}
const hideLoading = function() {
	store.commit('loading/hideLoading')
}

import {
	createSSRApp
} from 'vue'
export function createApp() {
	const app = createSSRApp(App)
	app.use(createPinia()) // pinia
	app.provide('tui', tui)
	app.provide('$showLoading', showLoading)
	app.provide('$hideLoading', hideLoading)
	app.provide('compressImgUrl', function(src, w, h) {
		if (src.indexOf(appConfig.qiNiuDomain) != -1) {
			return `${src}?imageMogr2/thumbnail/${parseInt(w)}x${parseInt(h)}`
		} else {
			return src
		}
	})
	return {
		app
	}
}